package com.qf.lanzhou.blog.api.controller;

import com.qf.lanzhou.blog.api.pojo.entity.Tag;
import com.qf.lanzhou.blog.api.service.TagService;
import com.qf.lanzhou.blog.api.service.impl.TagServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author Yeach-chen
 * @ClassName GetTagListServlet
 */
@WebServlet("/getTag.do")
public class GetTagListServlet extends BaseServletPost{
    private TagService tagService=new TagServiceImpl();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String articleI = req.getParameter("articleId");
        int articleId = Integer.parseInt(articleI);
        System.out.println("-----文章TagID:"+articleI);
        List<Tag> tagList;
        try {
            tagList = tagService.getTagList(articleId);
            System.out.println("获取文章的Tag:"+tagList);
            successResultWrite(tagList,resp);
        }catch (RuntimeException e){
            String message = e.getMessage();
            failedResultWrite(message,resp);
        }
    }
}
